//------------------------------------------------------------------------------
///	\file ringbuffer.h
///
///	\brief
///	Ring Buffer header file
///
///	This ring buffer began life as a UART I/O mechanism.
///	It has advanced status information like high water-mark and items processed.
///
//	$Id: ringbuff.h 296 2014-09-27 06:22:38Z ac.verbeck@gmail.com $
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	The MIT License (MIT)
//
//	Copyright (c) 2014 A.C. Verbeck
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.

//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//------------------------------------------------------------------------------
#pragma once

//------------------------------------------------------------------------------
//  Ring buffer errors
//------------------------------------------------------------------------------
typedef enum {
	RB_RESET,
	RB_OK,
	RB_EMPTY,
	RB_FULL,
} RB_STATUS;

//------------------------------------------------------------------------------
//  Ring buffer types
//------------------------------------------------------------------------------
typedef	struct RING_BUFFERtag {
	uint8_t			*data_ptr;													///< Pointer to the data buffer
	uint8_t			*read_ptr;													///< Read (remove) pointer
	uint8_t			*write_ptr;													///< Write (add) pointer
	uint16_t		buff_sz;													///< Data buffer size
	uint16_t		curr_ct;													///< Current count
	uint16_t		water_mark;													///< High water mark
	uint32_t		total_ct;													///< Total number of items
	uint32_t		rb_full_ct;													///< Ring Buffer full count
	uint32_t		rb_empty_ct;												///< Ring Buffer empty count
	uint32_t		init;														///< Ring Buffer initialization status
	RB_STATUS		status;														///< Status for the ring buffer
} RING_BUFFER;

typedef	struct RING_BUFFER_STATtag {
	uint16_t		buff_sz;													///< Data buffer size
	uint16_t		curr_ct;													///< Current count
	uint16_t		water_mark;													///< High water mark
	uint32_t		total_ct;													///< Total number of items
	uint32_t		rb_full_ct;													///< Ring Buffer full count
	uint32_t		rb_empty_ct;												///< Ring Buffer empty count
} RING_BUFFER_STAT;

//------------------------------------------------------------------------------
//  Ring buffer public driver functions
//------------------------------------------------------------------------------
void		RingBuff_HW_Init(RING_BUFFER* rb, uint8_t *dp, uint16_t ct);
void		RingBuff_OS_Init(RING_BUFFER* rb);
RB_STATUS	RingBuff_GetStatus(RING_BUFFER* rb);

void		RingBuff_Add(RING_BUFFER* rb, uint8_t c);
void		RingBuff_Remove(RING_BUFFER* rb, uint8_t *c);
void		RingBuff_Clear(RING_BUFFER* rb);
void		RingBuff_GetStat(RING_BUFFER* rb, RING_BUFFER_STAT* rbs);
void		RingBuff_ClrStat(RING_BUFFER* rb);

bool		RingBuff_Full(RING_BUFFER* rb);
bool		RingBuff_Empty(RING_BUFFER* rb);

uint16_t	RingBuff_GetSize(RING_BUFFER* rb);
uint16_t	RingBuff_GetWaterMark(RING_BUFFER* rb);
uint16_t	RingBuff_GetCount(RING_BUFFER* rb);
uint32_t	RingBuff_GetTotalCount(RING_BUFFER* rb);
uint32_t	RingBuff_GetFullCount(RING_BUFFER* rb);
uint32_t	RingBuff_GetEmptyCount(RING_BUFFER* rb);

//
//	End: ringbuff.h
//
